function past(imageType) {
    window.location.href="/defaultIndexErr?imageType="+imageType;
}

function encryptPadding() {
    // 创建一个加密对象 使用该对象需要先引入jsencrypt.js文件
    //var encryptor = new JSEncrypt();
    var result1;
    // 获取公钥
    $.ajax({
        type: "post",
        async: false,
        url:  "/getPublicKey",
        success: function (result) {
            // 把公钥放到加密对象中
            //encryptor.setPublicKey(result);

           result1=result;
        }
    });
    return result1;




}



var input1Flag=false;
var input2Flag=false


/**
 * //获得焦点弹出提示
 */
var tips1;

$(document).on("focus","#input_reset1",function () {

    tips1=layer.tips('<span class="span_tiShiDefalt span_tiShi">长度8-15位</span>' +
        '</br>' +
        '<span class="span_tiShiDefalt span_tiShi">包含字母和数字</span>' +
        '</br>' +
        '<span class="span_tiShi3">可有特殊符号</span>', '#input_reset1', {
        tips: [2, '#2b7edf'],
        time:0
    });
    guiZeChuLi($(this))
})
$(document).on("blur","#input_reset1",function () {
    layer.close(tips1)
})


var tips2;
$(document).on("focus","#input_reset2",function () {

    tips2=layer.tips('<span id="span_tiShi2" style="color: red">密码不一致</span>', '#input_reset2', {
        tips: [2, '#2b7edf'],
        time:0
    });
    guiZeChuLi2()
})
$(document).on("blur","#input_reset2",function () {
    layer.close(tips2)
})





/**
 * //点击眼睛切换
 */
$(document).on("click",".span_eye",function () {
    var inputType=$(this).prev().attr("type")
    if(inputType=="text"){
        $(this).prev().prop("type","password")
        $(this).toggleClass("g_button_z_eye g_button_z_eyeSlash")
    }else if(inputType=="password"){
        $(this).prev().prop("type","text")
        $(this).toggleClass("g_button_z_eye g_button_z_eyeSlash")
    }
})

/**
 *  验证规则处理 span_successTiShi span_errorTiShi span_tiShiDefalt
 */
$(document).on("input propertychange","#input_reset1",function (e) {
    guiZeChuLi($(this))
})


//确认密码处理
var input2Flag=false
$(document).on("input propertychange","#input_reset2",function () {
    guiZeChuLi2()
})


/**
 * 提交
 * */
$(document).on("click","#button_ok",function () {
    if(!input1Flag){
        layer.msg('密码规则错误！');
    }else{
        if(!input2Flag){
            layer.msg('密码不一致！');
        }else{
            if(input2Flag&&input1Flag){
                var result = encryptPadding();
                var encryptor = new JSEncrypt();
                encryptor.setPublicKey(result);
                var pass2=encryptor.encrypt($("#input_reset2").val())
                //请求重置密码
                $.ajax({
                    async:false,
                    url:"/initPassReset",
                    type: "post",
                    data:{"newPwd":pass2},
                    dataType:"JSON",
                    success:function (data) {
                        if(!data.flag){
                            var layerLoadindex=layer.alert(data.msg, {
                                anim: 1
                                , btn: ['确认']
                                , icon: 5
                                , yes: function () {
                                    layer.close(layerLoadindex);
                                }

                            });
                        }else{
                            layer.closeAll()
                            layer.msg('请重新登录！');
                        }
                    },
                    error:function (e) {
                        var layerLoadindex=layer.alert(e, {
                            anim: 1
                            , btn: ['确认']
                            , icon: 5
                            , yes: function () {
                                layer.close(layerLoadindex);
                            }

                        });
                    }
                })

            }
        }
    }

})





/**
 * 切换成功或错误颜色
 * @param a
 * @param b
 * @param c
 * @param index
 */
function queHuanClass(a,b,c,index) {
    $(".span_tiShi").eq(index).removeClass(a)
    $(".span_tiShi").eq(index).removeClass(b)
    $(".span_tiShi").eq(index).addClass(c)
}

/**
 * 第一个输入框校验处理
 * @param e
 */
function guiZeChuLi(e) {
    var pass=e.val()
    if(pass.length>=8&&pass.length<=15){
        //切换绿色
        queHuanClass("span_tiShiDefalt","span_errorTiShi","span_successTiShi",0)
        var rex1=/^[^\s]*$/
        var rex2=/^(?=.*[a-zA-Z])(?=.*[0-9])[a-zA-Z0-9]{8,15}$/

        //是否包含空格
        if(!rex1.test(pass)){
            queHuanClass("span_tiShiDefalt","span_successTiShi","span_errorTiShi",1)
            input1Flag=false
        }else{
            //判断是否包含数字和字母
            if(!rex2.test(pass)){
                queHuanClass("span_tiShiDefalt","span_successTiShi","span_errorTiShi",1)
                input1Flag=false
            }else{
                queHuanClass("span_tiShiDefalt","span_errorTiShi","span_successTiShi",1)
                input1Flag=true
            }
        }
    }else{
        //切换红色
        queHuanClass("span_tiShiDefalt","span_successTiShi","span_errorTiShi",0)
        input1Flag=false
    }
}



/**
 * 第二个输入框校验处理
 * @param e
 */
function guiZeChuLi2() {
    var pass1=$("#input_reset1").val()
    var pass2=$("#input_reset2").val()
    if(pass1==pass2){
        $("#span_tiShi2").text("密码一致！").css("color","rgba(14, 229, 14, 0.99)")
        input2Flag=true
    }else{
        $("#span_tiShi2").text("密码不一致！").css("color","red")
        input2Flag=false
    }
}





/**
 * 切换成功或错误颜色
 * @param a
 * @param b
 * @param c
 * @param index
 */
function queHuanClass(a,b,c,index) {
    $(".span_tiShi").eq(index).removeClass(a)
    $(".span_tiShi").eq(index).removeClass(b)
    $(".span_tiShi").eq(index).addClass(c)
}

/**
 * 第一个输入框校验处理
 * @param e
 */
function guiZeChuLi(e) {
    var pass=e.val()
    if(pass.length>=8&&pass.length<=15){
        //切换绿色
        queHuanClass("span_tiShiDefalt","span_errorTiShi","span_successTiShi",0)
        var rex1=/^[^\s]*$/
        var rex2=/^(?=.*[a-zA-Z])(?=.*[0-9])[a-zA-Z0-9]{2,10}$/

        //是否包含空格
        if(!rex1.test(pass)){
            queHuanClass("span_tiShiDefalt","span_successTiShi","span_errorTiShi",1)
            input1Flag=false
        }else{
            //判断是否包含数字和字母
            if(!rex2.test(pass)){
                queHuanClass("span_tiShiDefalt","span_successTiShi","span_errorTiShi",1)
                input1Flag=false
            }else{
                queHuanClass("span_tiShiDefalt","span_errorTiShi","span_successTiShi",1)
                input1Flag=true
            }
        }
    }else{
        //切换红色
        queHuanClass("span_tiShiDefalt","span_successTiShi","span_errorTiShi",0)
        input1Flag=false
    }
}



/**
 * 第二个输入框校验处理
 * @param e
 */
function guiZeChuLi2() {
    var pass1=$("#input_reset1").val()
    var pass2=$("#input_reset2").val()
    if(pass1==pass2){
        $("#span_tiShi2").text("密码一致！").css("color","rgba(14, 229, 14, 0.99)")
        input2Flag=true
    }else{
        $("#span_tiShi2").text("密码不一致！").css("color","red")
        input2Flag=false
    }
}
